<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class AddPriceToChargeRecordsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('charge_records', function (Blueprint $table) {
            if (!Schema::hasColumn('charge_records', 'price')) {
                $table->float('price')->default(0.5);
            }
            if (!Schema::hasColumn('charge_records', 'discharge_money')) {
                $table->double('discharge_money')->nullable();
            }
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('charge_records', function (Blueprint $table) {
            if (Schema::hasColumn('charge_records', 'price')) {
                $table->dropColumn('price');
            }
            if (Schema::hasColumn('charge_records', 'discharge_money')) {
                $table->dropColumn('discharge_money');
            }
        });
    }
}
